import { getQueryPageApi } from "@/api/approval/approvalManagement";
import { getUserByPositionApi } from "@/api/managementCenter/departmentPersonnel";
import { getCustomerSelectList } from "@/api/managementCenter/customerManagement";

import { reactive } from "vue";

export const searchItemList: Array<SuperSearch.SearchItem> = [
  {
    type: "input",
    label: "运单号",
    keyName: "waybillNumList",
    placeholder: "支持批量(空格/逗号隔开)"
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "客户简称",
    keyName: "customerIdList",
    optionsRequest: getCustomerSelectList,
    optReqParams: { isFilterChild: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    attrs: {
      mode: "multiple"
    },
    optConfig: {
      label: "shortName",
      value: "id"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "问题件类型",
    keyName: "problemPieceTypeList",
    optionsRequest: getQueryPageApi,
    optReqParams: { pageNum: 1, pageSize: 100 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "type",
      value: "type"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "业务员",
    keyName: "bizIdList",
    optionsRequest: getUserByPositionApi,
    optReqParams: { position: "4", status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "username",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "创建人",
    keyName: "createByList",
    optionsRequest: getUserByPositionApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "username",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },

    options: []
  }),
  {
    type: "datetimerange",
    label: "创建时间",
    keyName: "time"
  }
];

// 列表
export const tableColumn: Array<SuperTable.TableCoulmnItem | SuperTable.NestTableColumnItem> = [
  {
    type: "checkbox",
    field: "checkbox",
    minWidth: "50",
    fixed: "left"
  },
  {
    field: "waybillNum",
    title: "运单号",
    minWidth: "140"
  },
  {
    field: "shortName",
    title: "客户简称",
    minWidth: "140"
  },
  {
    field: "customerName",
    title: "客户名称",
    minWidth: "220"
  },
  {
    field: "depositTime",
    title: "拣货时间",
    minWidth: "140",
    formatter: "formatDate"
  },
  {
    field: "outWarehouseBrokerName",
    title: "代理",
    minWidth: "160"
  },
  {
    field: "channelName",
    title: "预报渠道",
    minWidth: "160"
  },
  {
    field: "agentChannelName",
    title: "代理渠道",
    minWidth: "160"
  },
  {
    field: "problemPieceType",
    title: "问题件类型",
    minWidth: "140"
  },
  {
    field: "description",
    title: "描述",
    minWidth: "120"
  },
  {
    field: "totalPrice",
    title: "问题件金额",
    minWidth: "140"
  },
  {
    field: "proportion",
    title: "分摊比例",
    minWidth: "140"
  },
  {
    field: "proportionPrice",
    title: "分摊金额",
    minWidth: "160"
  },
  {
    field: "innerRemark",
    title: "内部备注",
    minWidth: "140"
  },
  {
    field: "margin",
    title: "毛利润",
    minWidth: "100"
  },
  {
    field: "checkingStatus",
    title: "对账状态",
    minWidth: "80",
    renderSlot: "checkingStatus"
  },
  {
    field: "companyName",
    title: "经营单位",
    minWidth: "80"
  },
  {
    field: "bizName",
    title: "业务",
    minWidth: "80"
  },
  {
    field: "finName",
    title: "财务",
    minWidth: "80"
  },

  {
    field: "adjustPrice",
    title: "调整运费",
    minWidth: "140"
  },
  {
    field: "cargoShapeRatio",
    title: "货型比",
    minWidth: "140"
  },
  {
    field: "accountName",
    title: "账期",
    minWidth: "140"
  }
];
